<!DOCTYPE HTML>
<html lang="zh-CN" class="sidebar-visible no-js rust">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>交叉编译 - Hello-Embedded-Linux</title>


        <!-- Custom HTML head -->

        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="嵌入式Linux系统基本操作介绍。Introduction to basic operation of Embedded-Linux system.">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <link rel="icon" href="favicon.svg">
        <link rel="shortcut icon" href="favicon.png">
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        <link rel="stylesheet" href="css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->

    </head>
    <body>
        <!-- Provide site root to javascript -->
        <script type="text/javascript">
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "rust";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('rust')
            html.classList.add(theme);
            html.classList.add('js');
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="README_zh.html">Hello-Embedded-Linux</a></li><li class="chapter-item expanded affix "><li class="part-title">认识和操作嵌入式 Linux 系统</li><li class="chapter-item expanded "><a href="系统初始化.html"><strong aria-hidden="true">1.</strong> 系统初始化</a></li><li class="chapter-item expanded "><a href="命令行-vi和shell.html"><strong aria-hidden="true">2.</strong> 命令行 - vi 和 shell</a></li><li class="chapter-item expanded "><a href="系统资源及其配置.html"><strong aria-hidden="true">3.</strong> 系统资源及其配置</a></li><li class="chapter-item expanded "><a href="交叉编译.html" class="active"><strong aria-hidden="true">4.</strong> 交叉编译</a></li><li class="chapter-item expanded "><a href="硬件设备操作.html"><strong aria-hidden="true">5.</strong> 硬件设备操作</a></li><li class="chapter-item expanded "><a href="网络操作.html"><strong aria-hidden="true">6.</strong> 网络操作</a></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky bordered">
                    <div class="left-buttons">
                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </button>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust (default)</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">Hello-Embedded-Linux</h1>

                    <div class="right-buttons">
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                        <a href="https://github.com/HeyGoda/Hello-Embedded-Linux" title="Git repository" aria-label="Git repository">
                            <i id="git-repository-button" class="fa fa-github"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <ul>
<li><a href="#%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91">交叉编译</a>
<ul>
<li><a href="#%E4%B8%80%E4%BA%9B%E5%BC%80%E6%BA%90%E7%A8%8B%E5%BA%8F%E9%92%88%E5%AF%B9-arm-%E8%8A%AF%E7%89%87%E7%9A%84%E7%BC%96%E8%AF%91%E6%96%B9%E6%B3%95">一些开源程序针对 ARM 芯片的编译方法</a>
<ul>
<li><a href="#busybox">BusyBox</a></li>
<li><a href="#glibc">glibc</a></li>
<li><a href="#gdb">GDB</a></li>
<li><a href="#iw">iw</a></li>
<li><a href="#wpa_supplicant">wpa_supplicant</a></li>
<li><a href="#tcpdump">TCPDUMP</a></li>
<li><a href="#ntp">NTP</a></li>
<li><a href="#opus">Opus</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="交叉编译"><a class="header" href="#交叉编译">交叉编译</a></h2>
<p>嵌入式 Linux 系统中的应用程序由特定的交叉编译工具链编译得到，此工具链一般由芯片原厂提供或指定，因为系统的内核、libc 等程序运行的基础环境都由该工具链编译得到，所以应用程序最好也用此工具工具链来编译；</p>
<p>尽管如此，依然可以使用通用的交叉编译工具链来做测试，例如在 Ubuntu 下可以安装 <a href="https://packages.ubuntu.com/bionic/gcc-arm-linux-gnueabi">gcc-arm-linux-gnueabi</a> 或 <a href="https://packages.ubuntu.com/bionic/gcc-arm-linux-gnueabihf">gcc-arm-linux-gnueabihf</a> 来编译针对 ARM 芯片的程序：</p>
<pre><code class="language-shell">sudo apt install gcc-arm-linux-gnueabihf
</code></pre>
<p>编译方法可大致分为以下 2 种：</p>
<ul>
<li>
<p>自己写的代码直接使用工具链编译即可；</p>
<pre><code class="language-shell">arm-linux-gnueabihf-gcc main.c -o main.elf
</code></pre>
</li>
<li>
<p>公开的开源程序，一般使用下面的步骤编译：</p>
<pre><code class="language-shell">./configure --prefix=$(pwd)/cross_install --host=arm-linux-gnueabihf
make
make install
</code></pre>
<p>需要注意的是：</p>
<p>1、有的程序在以上步骤之前，需要先调用 <code>autogen.sh</code> 生成 <code>configure</code> 文件；</p>
<p>2、执行 <code>configure</code> 时可以传入不同的参数，可以执行 <code>./configure -h</code> 进行学习；</p>
<p>3、执行 <code>make</code> 时也可以传入不同的参数进行编译配置，可以阅读 Makefile 来了解支持的配置；</p>
</li>
</ul>
<h3 id="一些开源程序针对-arm-芯片的编译方法"><a class="header" href="#一些开源程序针对-arm-芯片的编译方法"><strong>一些开源程序针对 ARM 芯片的编译方法</strong></a></h3>
<p><em>如无特别说明，下面交叉编译后生成的文件均在 cross_install 目录中，只要将该目录下的文件拷贝到嵌入式设备上对应的目录即可正常使用；</em></p>
<h4 id="busybox"><a class="header" href="#busybox"><a href="https://busybox.net/">BusyBox</a></a></h4>
<p><a href="https://baike.baidu.com/item/busybox">BusyBox</a> 是一个集成了三百多个最常用 Linux 命令和工具的软件。BusyBox 包含了一些简单的工具，例如 ls、cat和echo等等，还包含了一些更大、更复杂的工具，例 grep、find、mount 以及 telnet 。有些人将 BusyBox 称为 Linux 工具里的瑞士军刀。简单的说 BusyBox 就好像是个大工具箱，它集成压缩了 Linux 的许多工具和命令，也包含了 Linux 系统的自带的 shell。</p>
<ul>
<li>
<p>下载代码，并更新到最近的稳定版本：</p>
<pre><code class="language-shell"># download_busybox.sh

git clone git://git.busybox.net/busybox
cd busybox
git reset --hard 1_33_2
</code></pre>
</li>
<li>
<p>采用默认配置，参考 https://busybox.net/FAQ.html 和 <code>Makefile</code> 进行交叉编译</p>
<pre><code class="language-shell"># build_busybox.sh

make defconfig
make -j 4 CROSS_COMPILE=arm-linux-gnueabihf-
# 以下为静态编译
# LDFLAGS=&quot;--static&quot; make -j 4 CROSS_COMPILE=arm-linux-gnueabihf-
make install
# 编译后生成的可执行程序在 _install 目录下
</code></pre>
</li>
</ul>
<p>BusyBox 使用参考链接：<a href="https://busybox.net/downloads/BusyBox.html">BusyBox - The Swiss Army Knife of Embedded Linux</a></p>
<h4 id="glibc"><a class="header" href="#glibc"><a href="https://www.gnu.org/software/libc/">glibc</a></a></h4>
<p><a href="https://baike.baidu.com/item/glibc/10058561">glibc</a> 是 GNU 发布的 libc 库，即 c 运行库。glibc 是 linux 系统中最底层的 api，几乎其它任何运行库都会依赖于 glibc。glibc 除了封装 linux 操作系统所提供的系统服务外，它本身也提供了许多其它一些必要功能服务的实现。由于 glibc 囊括了几乎所有的 UNIX 通行的标准，可以想见其内容包罗万象。而就像其他的 UNIX 系统一样，其内含的档案群分散于系统的树状目录结构中，像一个支架一般撑起整个操作系统。在 GNU/Linux 系统中，其 C 函式库发展史点出了 GNU/Linux 演进的几个重要里程碑，用 glibc 作为系统的 C 函式库，是 GNU/Linux 演进的一个重要里程碑。</p>
<ul>
<li>
<p>下载代码并更新到需要的版本：</p>
<pre><code class="language-shell"># download_glibc.sh

git clone https://sourceware.org/git/glibc.git &amp;&amp; cd glibc &amp;&amp; git reset --hard glibc-2.34 &amp;&amp; cd -
</code></pre>
</li>
<li>
<p>编译：</p>
<pre><code class="language-shell"># build_glibc.sh

cd glibc

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}
BUILD_DIR=cross_build
mkdir -p ${BUILD_DIR}

cd ${BUILD_DIR}
../configure --prefix=$(pwd)/../${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
        if false; then
                make uninstall
                make clean
        fi
        make -j 20
                make install
}
</code></pre>
</li>
</ul>
<h4 id="gdb"><a class="header" href="#gdb"><a href="https://sourceware.org/gdb/">GDB</a></a></h4>
<p><a href="http://www.gdbtutorial.com/tutorial/what-gdb">GDB</a> 或 GNU 项目调试器是 GNU 项目，用于调试应用程序并分析程序执行期间发生的情况，允许开发者查看在另一个程序执行时“内部”发生了什么——或者另一个程序在它崩溃时正在做什么。 </p>
<ul>
<li>
<p>下载代码并更新到需要的版本：</p>
<pre><code class="language-shell"># download_gdb.sh

# git clone git://sourceware.org/git/binutils-gdb.git
# 镜像下载
git clone https://mirrors.tuna.tsinghua.edu.cn/git/binutils-gdb.git &amp;&amp; cd binutils-gdb &amp;&amp; git reset --hard gdb-10.2-release &amp;&amp; cd -
</code></pre>
</li>
<li>
<p>编译：</p>
<pre><code class="language-shell"># build_gdb.sh

cd binutils-gdb

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
        if true; then
                make uninstall
                make clean
        fi
        # 根据编译环境使用并行编译加快速度
        make -j20 &amp;&amp; make install
}
</code></pre>
</li>
</ul>
<p>GDB 使用参考链接：<a href="https://www.yanbinghu.com/2019/04/20/41283.html">GDB调试指南</a>、<a href="http://www.gdbtutorial.com/tutorial/what-gdb">GDB Tutorial</a></p>
<h4 id="iw"><a class="header" href="#iw"><a href="https://wireless.wiki.kernel.org/en/users/documentation/iw">iw</a></a></h4>
<p>iw 是一个无线设备命令行配置工具，支持内核中所有基于 nl80211 的驱动程序。 旧工具 <a href="https://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html">Wireless Tools for Linux（iwconfig）</a> 已弃用，强烈建议切换到 iw。</p>
<p>iw 依赖 libnl 库。</p>
<ul>
<li>
<p>下载代码并更新到需要的版本：</p>
<pre><code class="language-shell"># download_iw.sh

git clone git://github.com/tgraf/libnl.git &amp;&amp; cd libnl &amp;&amp; git reset --hard libnl3_2_25 &amp;&amp; cd -
git clone http://git.sipsolutions.net/iw.git/ &amp;&amp; cd iw &amp;&amp; git reset --hard v5.9 &amp;&amp; cd -
</code></pre>
</li>
<li>
<p>编译 libnl：</p>
<pre><code class="language-shell"># build_libnl.sh

cd libnl
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
        if true; then
                make uninstall
                make clean
        fi
        make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 iw</p>
<pre><code class="language-shell"># build_iw.sh

cd iw
make PREFIX=./cross_install PKG_CONFIG_PATH=../libnl/cross_install/lib/pkgconfig CC=arm-linux-gnueabihf-gcc
</code></pre>
</li>
</ul>
<p>iw 使用参考链接：<a href="https://ywnz.com/linux/iw/">Linux iw命令使用详解</a>、<a href="https://wireless.wiki.kernel.org/en/users/documentation/iw/replace-iwconfig">replace-iwconfig Linux Wireless</a></p>
<h4 id="wpa_supplicant"><a class="header" href="#wpa_supplicant"><a href="https://w1.fi/wpa_supplicant/">wpa_supplicant</a></a></h4>
<p><a href="http://blog.chinaunix.net/uid-29181887-id-4826168.html"><strong>WPA</strong> </a>是 WiFi Protected Access 的缩写，中文含义为 “ WiFi 网络安全存取 ” 。WPA 是一种基于标准的可互操作的 WLAN 安全性增强解决方案，可大大增强现有以及未来无线局域网络的数据保护和访问控制水平。</p>
<p><a href="https://segmentfault.com/a/1190000011579147"><strong>wpa_supplicant</strong></a> 是一个连接、配置 WIFI 的工具，它主要包含 wpa_supplicant 与 wpa_cli 两个程序。通常情况下，可以通过 wpa_cli 来进行 WIFI 的配置与连接，如果有特殊的需要，可以编写应用程序直接调用 wpa_supplicant 的接口直接开发。</p>
<p><a href="https://www.cnblogs.com/hokori/p/14168584.html">wpa_supplicant</a> 的编译依赖 <a href="https://www.openssl.org/">openssl</a> 和 <a href="https://www.infradead.org/%7Etgr/libnl/">libnl</a>。</p>
<ul>
<li>
<p>下载代码并更新到需要的版本：</p>
<pre><code class="language-shell"># download_wpa.sh

git clone git://github.com/tgraf/libnl.git &amp;&amp; cd libnl &amp;&amp; git reset --hard libnl3_2_25 &amp;&amp; cd -
git clone git://git.openssl.org/openssl.git &amp;&amp; cd openssl &amp;&amp; git reset --hard OpenSSL_1_1_1 &amp;&amp; cd -
git clone git://w1.fi/srv/git/hostap.git &amp;&amp; cd hostap &amp;&amp; git reset --hard hostap_2_9 &amp;&amp; cd -
</code></pre>
</li>
<li>
<p>编译 libnl</p>
<pre><code class="language-shell"># build_libnl.sh

cd libnl
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
        if true; then
                make uninstall
                make clean
        fi
        make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 openssl</p>
<pre><code class="language-shell"></code></pre>
</li>
</ul>
<h1 id="build_opensslsh"><a class="header" href="#build_opensslsh">build_openssl.sh</a></h1>
<p>cd openssl</p>
<p>INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}</p>
<p>./Configure linux-generic32 –prefix=$(pwd)/${INSTALL_DIR} <br />
-lpthread <br />
–cross-compile-prefix=arm-linux-gnueabihf- &amp;&amp; {
if true; then
make uninstall
make clean
fi
make depend &amp;&amp; make &amp;&amp; make install
}</p>
<pre><code>
- 编译 wpa_supplicant

首先，复制缺省编译配置文件

```shell
cd hostap/wpa_supplicant
cp defconfig .config
</code></pre>
<p>接着编辑 .config 文件，加入以下配置：</p>
<pre><code class="language-makefile"># 使用 WEXT 通过 ioctl 和驱动通信，典型工具如：ifconfig
CONFIG_DRIVER_WEXT=y

# 使用 NL80211 通过一个特殊的 socket 和驱动通信，典型工具如：iwconfig，使能该选项时需指定 libnl 库
CONFIG_DRIVER_NL80211=y

# 指定 libnl 版本及其库文件位置
CONFIG_LIBNL32=y
CFLAGS += -I../../libnl/cross_install/include/libnl3/
LIBS += -L../../libnl/cross_install/lib/

# 使用 openssl 作为 TLS 加密库并指定其位置
CONFIG_TLS = openssl
CFLAGS += -I../../openssl/cross_install/include/
LIBS += -L../../openssl/cross_install/lib/
</code></pre>
<p>并注释掉dbus相关的配置（需要的话请另外编译dbus）：</p>
<pre><code class="language-makefile">#CONFIG_CTRL_IFACE_DBUS_NEW=y
#CONFIG_CTRL_IFACE_DBUS_INTRO=y
</code></pre>
<p>然后进行交叉编译：</p>
<pre><code class="language-shell"># build_wpa.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}
export LIBDIR=$(pwd)/${INSTALL_DIR}/lib/
export INCDIR=$(pwd)/${INSTALL_DIR}/include/
export BINDIR=$(pwd)/${INSTALL_DIR}/bin/
make CC=arm-linux-gnueabihf-gcc 
make install
</code></pre>
<p>wpa_supplicant 使用参考链接：<a href="https://www.cnblogs.com/hokori/p/14168584.html">Linux 使用wpa_supplicant手动配置连接wifi</a></p>
<h4 id="tcpdump"><a class="header" href="#tcpdump"><a href="https://www.tcpdump.org/">TCPDUMP</a></a></h4>
<p>TCPDUMP 是 Linux 系统下的一个强大的命令，可以将网络中传送的数据包完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过滤，并提供 and、or、not 等逻辑语句来帮助你去掉无用的信息；TCPDUMP 依赖于开源库 <a href="https://www.cnblogs.com/coder2012/archive/2013/04/13/3012390.html"><strong>libpcap</strong></a> (无需单独编译，可以随 TCPDUMP 一起编译)；</p>
<ul>
<li>
<p>下载代码并更新到需要的版本：</p>
<pre><code class="language-shell"># download_tcpdump.sh

git clone https://github.com/the-tcpdump-group/tcpdump &amp;&amp; cd tcpdump &amp;&amp; git reset --hard tcpdump-4.99.1 &amp;&amp; cd -
</code></pre>
</li>
<li>
<p>编译 TCPDUMP：</p>
<pre><code class="language-shell"># build_tcpdump.sh

cd tcpdump

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
        if true; then
                make uninstall
                make clean
        fi
        make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>TCPDUMP 使用参考链接：<a href="https://zhuanlan.zhihu.com/p/74812069">Linux系统 tcpdump 抓包命令使用教程</a>、<a href="https://www.cnblogs.com/wongbingming/p/13212306.html">tcpdump 使用指南</a>、<a href="https://www.tcpdump.org/manpages/tcpdump.1.html">Man page of TCPDUMP</a>、<a href="https://danielmiessler.com/study/tcpdump/#ip6">A tcpdump Tutorial with Examples</a></p>
</li>
</ul>
<h4 id="ntp"><a class="header" href="#ntp"><a href="http://www.ntp.org/">NTP</a></a></h4>
<p><a href="https://baike.baidu.com/item/%E7%BD%91%E7%BB%9C%E6%97%B6%E9%97%B4%E5%8D%8F%E8%AE%AE/5927826">网络时间协议</a>，英文名称：Network Time Protocol（NTP）是用来使计算机时间同步化的一种协议，它可以使计算机对其服务器或时钟源（如石英钟，GPS 等等)做同步化，它可以提供高精准度的时间校正（LAN 上与标准间差小于 1 毫秒，WAN 上几十毫秒），且可介由加密确认的方式来防止恶毒的协议攻击。NTP 的目的是在无序的 Internet 环境中提供精确和健壮的时间服务。</p>
<p>ntp 依赖 openssl；</p>
<ul>
<li>
<p>下载代码：</p>
<pre><code class="language-shell"># download_ntp.sh

git clone https://github.com/openssl/openssl.git &amp;&amp; cd openssl &amp;&amp; git reset --hard OpenSSL_1_1_1 &amp;&amp; cd -

# github上为不稳定版本，可能编译失败
# git clone https://github.com/ntp-project/ntp.git 
# 直接下载稳定版本源码包
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p15.tar.gz &amp;&amp; tar -xzvf ntp-4.2.8p15.tar.gz -C ./
</code></pre>
</li>
<li>
<p>编译 openssl：</p>
<pre><code class="language-shell"># build_openssl.sh

cd openssl

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./Configure linux-generic32 --prefix=$(pwd)/${INSTALL_DIR} \
-lpthread \
--cross-compile-prefix=arm-linux-gnueabihf- &amp;&amp; {
    if true; then
        make uninstall
        make clean
    fi  
    make depend &amp;&amp; make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 ntp：</p>
<pre><code class="language-shell"># build_ntp.sh

cd ntp-4.2.8p15
./bootstrap

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf \
--with-yielding-select=no \
CFLAGS=&quot;-I$(pwd)/../openssl/cross_install/include&quot; \
LDFLAGS=&quot;-L$(pwd)/../openssl/cross_install/lib&quot; &amp;&amp; {
    if false; then
        make uninstall
        make clean
    fi  
    make &amp;&amp; make install
}
</code></pre>
</li>
</ul>
<p>NTP 使用参考链接：<a href="https://www.php.cn/linux-479820.html">linux同步时间命令</a></p>
<h4 id="opus"><a class="header" href="#opus"><a href="https://opus-codec.org/">Opus</a></a></h4>
<p><a href="https://baike.baidu.com/item/opus/680370">Opus</a> 是一个有损声音编码的格式，由 Xiph.Org 基金会开发，之后由 IETF（互联网工程任务组）进行标准化，目标是希望用单一格式包含声音和语音，取代 Speex 和 Vorbis，且适用于网络上低延迟的即时声音传输，标准格式定义于 RFC 6716 文件。Opus 格式是一个开放格式，使用上没有任何专利或限制。</p>
<p>Opus 包含有几个代码库，这里编译 opus-tools 编解码工具及其依赖库opus、opusfile、libopusenc、ogg、opunssl；</p>
<ul>
<li>
<p>下载代码并更新到需要的版本</p>
<pre><code class="language-shell"></code></pre>
</li>
</ul>
<h1 id="download_opussh"><a class="header" href="#download_opussh">download_opus.sh</a></h1>
<p>git clone https://github.com/xiph/opus.git &amp;&amp; cd opus &amp;&amp; git reset –hard v1.2.1 &amp;&amp; cd -
git clone https://github.com/xiph/opusfile.git &amp;&amp; cd opusfile &amp;&amp; git reset –hard v0.9 &amp;&amp; cd -
git clone https://github.com/xiph/libopusenc.git &amp;&amp; cd libopusenc &amp;&amp; git reset –hard v0.2.1 &amp;&amp; cd -
git clone https://github.com/xiph/ogg.git &amp;&amp; cd ogg &amp;&amp; git reset –hard v1.3.5 &amp;&amp; cd -
git clone https://github.com/openssl/openssl.git &amp;&amp; cd openssl &amp;&amp; git reset –hard OpenSSL_1_1_1 &amp;&amp; cd -
git clone https://github.com/xiph/opus-tools.git &amp;&amp; cd opus-tools &amp;&amp; git reset –hard v0.2 &amp;&amp; cd -</p>
<pre><code>
- 编译 opus

```shell
# build_opus.sh

cd opus
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
    if true; then
        make uninstall
        make clean
    fi  
    make &amp;&amp; make install
}
</code></pre>
<ul>
<li>
<p>编译 libopusenc</p>
<pre><code class="language-shell"># build_libopusenc.sh

cd libopusenc
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf \
--disable-examples \
DEPS_CFLAGS=&quot;-I../opus/${INSTALL_DIR}/include/opus/ -I../opus/${INSTALL_DIR}/include/&quot; \
DEPS_LIBS=&quot;-L../opus/${INSTALL_DIR}/lib/&quot; &amp;&amp; {
    if true; then
        make uninstall
        make clean
    fi  
    make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 opusfile</p>
<pre><code class="language-shell"># build_opusfile.sh

cd opusfile
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf \
--disable-examples  \
DEPS_CFLAGS=&quot;-I../ogg/${INSTALL_DIR}/include/ -I../opus/${INSTALL_DIR}/include/opus/ -I../opus/${INSTALL_DIR}/include/&quot; \
URL_DEPS_CFLAGS=&quot;-I../openssl/${INSTALL_DIR}/include/ &quot; \
DEPS_LIBS=&quot;-L../ogg/${INSTALL_DIR}/lib/ -L../opus/${INSTALL_DIR}/lib/&quot; \
URL_DEPS_LIBS=&quot;-L../openssl/${INSTALL_DIR}/lib/&quot; &amp;&amp; {
    if true; then
        make uninstall
        make clean
    fi  
    make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 ogg</p>
<pre><code class="language-shell"># build_ogg.sh

cd ogg
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf &amp;&amp; {
    if true; then
        make uninstall
        make clean
    fi  
    make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 openssl</p>
<pre><code class="language-shell"># build_openssl.sh

cd openssl

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

./Configure linux-generic32 --prefix=$(pwd)/${INSTALL_DIR} \
-lpthread \
--cross-compile-prefix=arm-linux-gnueabihf- &amp;&amp; {
    if true; then
        make uninstall
        make clean
    fi  
    make depend &amp;&amp; make &amp;&amp; make install
}
</code></pre>
</li>
<li>
<p>编译 opus-tools</p>
<pre><code class="language-shell"># build_opus_tools.sh

cd opus-tools
./autogen.sh

INSTALL_DIR=cross_install
mkdir -p ${INSTALL_DIR}

if false; then
    echo &quot;Static library build&quot;
    ./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf \
        --without-flac \
        CFLAGS=&quot;-lm -ldl -pthread -I../opusfile/${INSTALL_DIR}/include/ -I../opusfile/${INSTALL_DIR}/include/opus/&quot; \
        OGG_CFLAGS=&quot;-I../ogg/${INSTALL_DIR}/include/&quot; \
        OGG_LIBS=&quot;-L../ogg/${INSTALL_DIR}/lib/ ../ogg/${INSTALL_DIR}/lib/libogg.a&quot; \
        OPUS_CFLAGS=&quot;-I../opus/${INSTALL_DIR}/include/ -I../opus/${INSTALL_DIR}/include/opus/&quot; \
        OPUS_LIBS=&quot;-L../opus/${INSTALL_DIR}/lib/ ../opus/${INSTALL_DIR}/lib/libopus.a \
-L../opusfile/${INSTALL_DIR}/lib/ ../opusfile/${INSTALL_DIR}/lib/libopusfile.a \
-L../openssl/${INSTALL_DIR}/lib/ ../openssl/${INSTALL_DIR}/lib/libssl.a ../openssl/${INSTALL_DIR}/lib/libcrypto.a \
-L../ogg/${INSTALL_DIR}/lib/ ../ogg/${INSTALL_DIR}/lib/libogg.a&quot; \
        OPUSFILE_CFLAGS=&quot;-I../opusfile/${INSTALL_DIR}/include/ -I../opusfile/${INSTALL_DIR}/include/opus/&quot; \
        OPUSFILE_LIBS=&quot;-L../opusfile/${INSTALL_DIR}/lib/ ../opusfile/${INSTALL_DIR}/lib/libopusfile.a&quot; \
        LIBOPUSENC_CFLAGS=&quot;-I../libopusenc/${INSTALL_DIR}/include/ -I../libopusenc/${INSTALL_DIR}/include/opus/&quot; \
        LIBOPUSENC_LIBS=&quot;-L../libopusenc/${INSTALL_DIR}/lib/ ../libopusenc/${INSTALL_DIR}/lib/libopusenc.a&quot; \
        OPUSURL_LIBS=&quot;-L../opusfile/${INSTALL_DIR}/lib/ ../opusfile/${INSTALL_DIR}/lib/libopusurl.a&quot; \
        OPUSURL_CFLAGS=&quot;-I../opusfile/${INSTALL_DIR}/include/&quot;
else
    echo &quot;Shared library build&quot;
    ./configure --prefix=$(pwd)/${INSTALL_DIR} --host=arm-linux-gnueabihf \
        --without-flac \
        CFLAGS=&quot;-I../opusfile/${INSTALL_DIR}/include/ -I../opusfile/${INSTALL_DIR}/include/opus/&quot; \
        OGG_CFLAGS=&quot;-I../ogg/${INSTALL_DIR}/include/&quot; \
        OGG_LIBS=&quot;-L../ogg/${INSTALL_DIR}/lib/ -logg&quot; \
        OPUS_CFLAGS=&quot;-I../opus/${INSTALL_DIR}/include/ -I../opus/${INSTALL_DIR}/include/opus/&quot; \
        OPUS_LIBS=&quot;-L../opus/${INSTALL_DIR}/lib/ -lopus \
-L../opusfile/${INSTALL_DIR}/lib/ -lopusfile \
-L../openssl/${INSTALL_DIR}/lib/ -lssl -lcrypto \
-L../ogg/${INSTALL_DIR}/lib/ -logg&quot; \
        OPUSFILE_CFLAGS=&quot;-I../opusfile/${INSTALL_DIR}/include/ -I../opusfile/${INSTALL_DIR}/include/opus/&quot; \
        OPUSFILE_LIBS=&quot;-L../opusfile/${INSTALL_DIR}/lib/ -lopusfile&quot; \
        LIBOPUSENC_CFLAGS=&quot;-I../libopusenc/${INSTALL_DIR}/include/ -I../libopusenc/${INSTALL_DIR}/include/opus/&quot; \
        LIBOPUSENC_LIBS=&quot;-L../libopusenc/${INSTALL_DIR}/lib/ -lopusenc&quot; \
        OPUSURL_LIBS=&quot;-L../opusfile/${INSTALL_DIR}/lib/ -lopusurl&quot; \
        OPUSURL_CFLAGS=&quot;-I../opusfile/${INSTALL_DIR}/include/&quot;
fi

if [ $? = &quot;0&quot; ]; then
    if true; then
        make uninstall
        make clean
    fi
    make &amp;&amp; make install
fi
</code></pre>
</li>
</ul>
<p>opus-tools 使用参考链接：<a href="https://opus-codec.org/docs/">Documentation – Opus Codec</a></p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="系统资源及其配置.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>

                            <a rel="next" href="硬件设备操作.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="系统资源及其配置.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>

                    <a rel="next" href="硬件设备操作.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>




        <script type="text/javascript">
            window.playground_copyable = true;
        </script>


        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>

        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->


    </body>
</html>
